import { queryDashBoardCharts, queryDashBoardMap } from '../services/dashboard';

export default {
  namespace: 'dashboard',

  state: {
    mapData:[],
    chartsData:{
      devChart:[],
      warnMonitor:[],
    },
  },

  effects: {
    *fetch_dashboard_charts({ payload }, { call, put }) {
      const response =yield call(queryDashBoardCharts, payload);
      response &&  (
        yield put({
          type: 'appendChartsData',
          payload:response.data,
        })
      )
    },

    *fetch_dashboard_map({ payload }, { call, put }) {
      const response =yield call(queryDashBoardMap, payload);
      response &&  (
        yield put({
          type: 'appendMapData',
          payload:response.data.list,
        })
      )
    },


  },

  reducers: {

    appendChartsData(state, action) {
      return {
        ...state,
        chartsData: action.payload,
      };
    },

    appendMapData(state, action) {
      return {
        ...state,
        mapData: action.payload,
      };
    },
    // changeLoading(state, action) {
    //   return {
    //     ...state,
    //     loading: {
    //       ...state.loading,
    //       ...action.payload,
    //     },
    //   };
    // },

    appendClearState(state, action) {
      return {
        ...state,
        mapData:[],
        chartsData:{
          devChart:[],
          warnMonitor:[],
        },
      };
    },
  },
};

